package com.flyme.module.base.provider.controller;

import cn.hutool.core.collection.CollectionUtil;
import com.flyme.common.core.model.ResultBody;
import com.flyme.common.core.model.query.CriteriaQuery;
import com.flyme.common.core.model.query.PagerInfo;
import com.flyme.common.core.model.query.PqGrid;
import com.flyme.common.core.utils.StringUtils;
import com.flyme.core.base.supper.controller.BaseController;
import com.flyme.core.base.supper.entity.EntityMap;
import com.flyme.module.base.client.api.SysRoleRemoteService;
import com.flyme.module.base.client.constants.BaseConstants;
import com.flyme.module.base.client.entity.SysAuthority;
import com.flyme.module.base.client.entity.SysKeyword;
import com.flyme.module.base.client.entity.SystemRole;
import com.flyme.module.base.provider.service.SysAuthorizeService;
import com.flyme.module.base.provider.service.SysKeywordService;
import com.flyme.module.base.provider.service.SysRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author zyf
 */
@Api(tags = "关键词管理")
@RestController
@RequestMapping("/keyword")
public class SysKeyWordController extends BaseController<SysKeywordService, SysKeyword> {


    /**
     * 关键词列表
     *
     * @return
     */
    @ApiOperation(value = "获取关键词列表", notes = "获取关键词列表")
    @PostMapping("/list")
    public ResultBody list(@ModelAttribute(value = "pagerInfo") PagerInfo pagerInfo) {
        CriteriaQuery cq = new CriteriaQuery<EntityMap>(pagerInfo);
        cq.select("id,keyword,count");
        PqGrid pqGrid = bizService.pageList(cq);
        return ResultBody.success(pqGrid);
    }

    /**
     * 添加关键词
     *
     * @param keyword
     * @return
     */
    @ApiOperation(value = "添加关键词", notes = "添加关键词")
    @PostMapping("/add")
    public ResultBody add(@ModelAttribute(value = "keyword") SysKeyword keyword) {
        keyword.setCount(0);
        boolean result = bizService.saveOrUpdate(keyword);
        return ResultBody.success(result);
    }



    /**
     * 删除关键词
     *
     * @param ids 关键词
     * @return
     */
    @ApiOperation(value = "删除关键词", notes = "删除关键词")
    @PostMapping("/delByIds")
    public ResultBody delByIds(@RequestParam String[] ids) {
        boolean result = bizService.removeByIds(CollectionUtil.toList(ids));
        return ResultBody.success(result);
    }
}
